﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace WPFLoaders
{
    [ValueConversion(typeof(int), typeof(Duration))]
    public class MultiplyIntToSecConverter : IValueConverter
    {
        private static readonly MultiplyIntToSecConverter StaticInstance = new MultiplyIntToSecConverter();

        public static MultiplyIntToSecConverter Instance { get { return StaticInstance; } }

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var multiplier = (int)System.Convert.ChangeType(value, typeof(int));
            var multiplySeconds = (double)System.Convert.ChangeType(parameter, typeof(double));

            return TimeSpan.FromSeconds(multiplier*multiplySeconds);
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
